package com.yzh.wanandroid.utils.binding

import androidx.databinding.BindingAdapter
import androidx.navigation.Navigation
import androidx.recyclerview.widget.RecyclerView
import com.yzh.wanandroid.StartNavigationDirections
import com.yzh.wanandroid.adapter.LoadStateFooterAdapter
import com.yzh.wanandroid.adapter.ProjectArticleListAdapter

@BindingAdapter("project_article_Adapter")
fun setAdapter(recyclerView: RecyclerView, adapter: ProjectArticleListAdapter) {
    adapter?.run {
        recyclerView.adapter = this
        recyclerView.adapter =
            adapter.withLoadStateFooter(footer = LoadStateFooterAdapter(retry = {
                adapter.retry()
            }))

        setOnClickListener { view, link ,title->
            val action = StartNavigationDirections.toWebInfo(link,title)
            Navigation.findNavController(view).navigate(action)
        }
    }
}